package com.crecheng.shop.util;

import com.alibaba.fastjson.JSON;

public class MyMessage {
    public static final String defaultError=new MyMessage(-1,"error",null).json();
    public static final String defaultSqlError=new MyMessage(-2,"Sql error",null).json();
    public static final String defaultSqlNotFoundError=new MyMessage(-3,"Sql not found",null).json();
    public static final String defaultSuccess=new MyMessage(1,"succsee",null).json();

    public int code;
    public String msg;
    public Object data;

    public MyMessage(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public MyMessage(String msg) {
        this.msg = msg;
    }

    public MyMessage(String msg,Object data) {
        this.msg = msg;
        this.data=data;
    }

    public MyMessage(){

    }

    public String json(){
        return JSON.toJSONString(this);
    }

    public static String toJson(String msg){
        return new MyMessage(msg).json();
    }

    public static String toJson(String msg,Object data){
        return new MyMessage(msg,data).json();
    }
}
